<template>
  <div class="front new-detail">
    <div class="header-box">
      <Header></Header>
    </div>
    <div class="new-container">
      <div class="mianbao">
        <span class="btn hover" @click="$router.push('/front-home')">首页</span>
        <span>></span>
        <span class="btn hover" @click="$router.push('/front-news')">资讯中心</span>
        <span>></span>
        <span class="btn">详情</span>
      </div>
      <div class="main">
        <div class="left">
          <h2>{{detail.name}}</h2>
          <div class="date">{{detail.createTime | formatDate}}</div>
          <p v-html="detail.remark"></p>
        </div>
        <div class="right">
          <div class="title">众茶国际新闻</div>
          <li v-for="(item,index) in newsList" :key="index" class="btn" @click="newSelect(item.id)">
            <h2>{{item.name}}</h2>
            <p>{{item.viceName}}</p>
            <div>{{item.createTime | formatDate}}</div>
          </li>
        </div>
      </div>
    </div>

    <div class="footer">
      <Footer></Footer>
    </div>
  </div>
</template>

<script>
import { getNewDetail, getNewData } from "@/api/front-home.js";
import Footer from "@/views/front/components/Footer";
import Header from "@/views/front/components/Header";
export default {
  filters: {
    formatDate(value) {
      if (!value) return ''
      return value.toString().split(' ')[0]
    }
  },
  data() {
    return {
      detail: {},
      listQuery: {
        pageNo: 1,
        pageSize: 4,
        code$in: "news,forum,exhibition",
      },
      newsList: [],
      id: 0
    };
  },
  components: {
    Footer,
    Header,
  },
  created() {
    this.id = this.$route.query.id;
    console.log(this.$route);
    this.getNewDetail(this.id);
    this.getNewData();
  },
  methods: {
    getNewDetail(id) {
      getNewDetail({ id: id }).then((res) => {
        this.detail = res;

        this.$nextTick(() => {
          // let imgList = document.querySelectorAll(".wscnph")
          let imgList = document.getElementsByTagName("img")
          if (imgList && imgList.length > 0) {
            imgList.forEach(img => {
              img.style.maxWidth = '100%';
            });
          }
        })
      });
    },
    getNewData() {
      getNewData(this.listQuery).then((res) => {
        this.newsList = res.list;
      });
    },
    newSelect(id) {
      if (id === this.id) {
        return
      }
      this.id = id
      this.getNewDetail(id);
    },
  },
};
</script>
<style >
.hover:hover {
  color: #965f29;
}
</style>
<style lang="scss" scoped>
.new-detail {
  .new-container {
    width: 1200px;
    margin: 0 auto;
    padding-bottom: 20px;
    .mianbao {
      height: 60px;
      line-height: 60px;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: 300;
      color: #000000;
    }
    .main {
      display: flex;
      .left {
        width: 900px;
        padding: 33px 49px;
        box-sizing: border-box;
        border: 1px solid #eeeeee;
        margin-right: 31px;
        h2 {
          text-align: center;
          font-size: 30px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #000000;
        }
        .date {
          margin: 15px 0px 20px;
          text-align: center;
          color: #555555;
        }
        p {
          line-height: 30px;
          margin-top: 49px;
          font-size: 18px;
          font-family: Microsoft YaHei;
          font-weight: 300;
          color: #555555;
        }
      }
      .right {
        width: 226px;
        padding: 0 8px;
        border: 1px solid #eeeeee;
        .title {
          padding: 0 10px;
          height: 52px;
          line-height: 52px;
          border-bottom: 1px solid #eeeeee;
        }
        > li {
          padding: 25px 8px;
          border-bottom: 1px solid #eeeeee;

          h2 {
            font-size: 18px;
            font-family: Microsoft YaHei;
            font-weight: 300;
            color: #000000;
          }
          > p {
            margin: 20px 0;
            color: #555555;
            font-size: 18px;
            font-family: Microsoft YaHei;
            font-weight: 300;
          }
          > div {
            color: #b5b5b5;
            font-size: 16px;
            font-weight: 300;
          }
        }
      }
    }
  }
}
</style>